package su.demo.config.datasourceConfigs;

/**
 * @author SuZuQi
 * @title: DataSourceContextHolder
 * @projectName ssm_multipledatasources
 * @description: TODO
 * @date 2019/9/5
 */
public class DataSourceContextHolder {

    private static final ThreadLocal<String> contextHolder = new InheritableThreadLocal<>() ;


    /**
     * 设置数据源
     * @param db
     */
    public static void setDataSource(String db ) {
        contextHolder.set(db) ;

    }


    /**
     * 获取数据源
     * @return
     */
    public static String getDataSource(){
        return contextHolder.get() ;
    }

    /**
     * 清除线程中数据
     */
    public static void clear(){
        contextHolder.remove();
    }
}
